import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_page/home_business/search_page/search_main_logic.dart';
import 'package:xvideos/hj_page/home_business/search_page/widget/search_app_bar.dart';
import 'package:xvideos/hj_page/home_business/search_page/widget/search_histoty_view.dart';
import 'package:xvideos/hj_page/home_business/search_page/widget/search_hot_tag_view.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/banner/ads_grid_view_widget.dart';

import '../widget/home_more_tab_menu.dart';

class SearchMainPage<T extends SearchMainLogic> extends StatelessWidget {
  SearchMainPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<T>(
      init: instanceController<T>(),
      builder: (logic) {
        return Scaffold(
          resizeToAvoidBottomInset: false,
          body: Column(
            children: [
              SearchAppBar(
                onSubmitted: (value) => logic.onSubmitted(value),
              ),
              Expanded(
                child: NestedScrollView(
                  headerSliverBuilder: (context, innerBoxIsScrolled) {
                    return [
                      SliverToBoxAdapter(
                        child: AdsGridViewWidget(
                          32,
                          isBannerStyle: false,
                          isBigStyle: false,
                          padding: EdgeInsets.symmetric(vertical: 12.h, horizontal: 12.w),
                        ),
                      ),
                      SliverToBoxAdapter(
                        child: SearchHistoryView(
                          onHistoryClick: (keyword) => logic.onSubmitted(keyword),
                        ),
                      ),
                      SliverToBoxAdapter(
                        child: SearchHotTagView(
                          type: logic.hotType,
                          onTagClick: (keyword) => logic.onSubmitted(keyword),
                        ),
                      ),
                    ];
                  },
                  body: Column(
                    children: [
                      12.sizeBoxH,
                      HomeMoreTabMenu(
                        logic.sortTypeList,
                        pageController: logic.pageController,
                        selectColor: Colors.white,
                        showIndicator: true,
                        // showIndicator: true,
                      ),
                      12.sizeBoxH,
                      Expanded(
                        child: PageView(
                          controller: logic.pageController,
                          children: logic.recommendChildren(),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
